---
title: Node
sort: 17
contributors:
  - sokra
  - skipjack
  - oneforwonder
  - Rob--W
  - byzyk
  - EugeneHlushko
  - anikethsaha
  - chenxsan
  - snitin315
---

The following Node.js options configure whether to polyfill or mock certain [Node.js globals](https://nodejs.org/docs/latest/api/globals.html).

This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/main/lib/NodeStuffPlugin.js) plugin.

W> As of webpack 5, You can configure only `global`, `__filename`/`import.meta.filename` or `__dirname`/`import.meta.dirname` under `node` option. If you're looking for how to polyfill `fs` alike in Node.js under webpack 5, please check [resolve.fallback](/configuration/resolve/#resolvefallback) for help.

## node

`false` `object`

**webpack.config.js**

```javascript
module.exports = {
  //...
  node: {
    global: false,
    __filename: false,
    __dirname: false,
  },
};
```

The `node` option may be set to `false` to completely turn off the `NodeStuffPlugin` plugin.

## node.global

`boolean` `'warn'`

T> If you are using a module which needs global variables in it, use `ProvidePlugin` instead of `global`.

See [the Node.js documentation](https://nodejs.org/api/globals.html#globals_global) for the exact behavior of this object.

Options:

- `true`: Provide a polyfill or using `globalThis` if supported by your environment, see the [`environment`](/configuration/output/#outputenvironment) option.
- `false`: Provide nothing. Code that expects this object may crash with a `ReferenceError`.
- `'warn'`: Show a warning when using `global`.

## node.\_\_filename

`boolean` `'mock' | 'warn-mock' | 'node-module' | 'eval-only'`

Options:

- `true`: The filename of the **input** file relative to the [`context` option](/configuration/entry-context/#context).
- `false`: Webpack won't touch your `__filename` and `import.meta.filename` code, which means you have the regular Node.js `__filename` and `import.meta.filename` behavior. The filename of the **output** file when run in a Node.js environment.
- `'mock'`: The fixed value `'/index.js'`.
- `'warn-mock'`: Use the fixed value of `'/index.js'` but show a warning.
- `'node-module'`: Replace `__filename` in CommonJS modules and `import.meta.filename` code in ES modules to `fileURLToPath(import.meta.url)` when `output.module` is enabled.
- `'eval-only'`: Defer the resolution of `__filename`/`import.meta.filename` to the Node.js runtime at execution time, but evaluate them in construction like `require`/`import` to properly resolve modules. Replace `__filename` with `import.meta.filename` and vice versa depending on the `output.module` option (if your environment does not support `import.meta.filename`, the fallback will be used using `import.meta.url` to get this value).

The default value can be affected by different [`target`](/configuration/target/):

- Defaults to `'eval-only'` if [`target`](/configuration/target/) is set to `'node'` or node-like environments (`async-node`, `electron`) or mixed targets (`web` and `node` together).
- Defaults to `'mock'` if [`target`](/configuration/target/) is set to `'web'` or web-like environments.

## node.\_\_dirname

`boolean` `'mock' | 'warn-mock' | 'node-module' | 'eval-only'`

Options:

- `true`: The dirname of the **input** file relative to the [`context` option](/configuration/entry-context/#context).
- `false`: Webpack won't touch your `__dirname` and `import.meta.dirname` code, which means you have the regular Node.js `__dirname` and `import.meta.dirname` behavior. The dirname of the **output** file when run in a Node.js environment.
- `'mock'`: The fixed value `'/'`.
- `'warn-mock'`: Use the fixed value of `'/'` but show a warning.
- `'node-module'`: Replace `__dirname` in CommonJS modules to `fileURLToPath(import.meta.url + "/..")` when `output.module` is enabled.
- `'eval-only'`: Defer the resolution of `__dirname`/`import.meta.dirname` to the Node.js runtime at execution time, but evaluate them in construction like `require`/`import` to properly resolve modules. Replace `__dirname` with `import.meta.dirname` and vice versa depending on the `output.module` option (if your environment does not support `import.meta.filename`, the fallback will be used using `import.meta.url` to get this value).

The default value can be affected by different [`target`](/configuration/target/):

- Defaults to `'eval-only'` if [`target`](/configuration/target/) is set to `'node'` or node-like environments (`async-node`, `electron`) or mixed targets (`web` and `node` together).
- Defaults to `'mock'` if [`target`](/configuration/target/) is set to `'web'` or web-like environments.
